/**
 * Created with IntelliJ IDEA.
 * User: xi
 * Date: 13-8-24
 * Time: 下午5:00
 * To change this template use File | Settings | File Templates.
 */
window.BASE_URL = "/services/api";
window.AllDocCrtl = function ($rootScope, $scope) {

    $scope.queryParams || ( $scope.queryParams = {});
    $scope.queryParams.pageSize = 15;

    var loadData = function () {
        $.ajax({
            url: BASE_URL + '/account/user/query',
            type: "GET",
            data: $scope.queryParams,
            dataType: "json",
            success: function (data) {
                $scope.pageData = pageToObj(data);
                $.each($scope.pageData.items, function (i, item) {
                    if (item.createTime) {
                        item.createTime_show = (new Date(item.createTime)).format('yyyy-MM-dd hh:mm:ss');
                    }
                });
                applyAngularScope($rootScope, $scope);
            }
        });
    }

    loadData();

    $scope.goPage = function (pageNo, className) {
        if (className == 'disabled') {
            return;
        }
        $scope.queryParams.pageNo = pageNo;
        loadData();
    }

    $scope.search = function () {
        $scope.queryParams.likeName = "nickName";
        $scope.queryParams.likeValue = $scope.keyWords;
        $scope.queryParams.pageNo = 1;
        loadData();
    }

    $scope.editUser = function (item) {
        window.top.current_edit_user = item;
        location.href = "./edit.html";
    }

    $scope.newUser = function () {
        location.href = "./edit.html";
    }


    $scope.delData = function (entityId, index) {
        if (confirm('是否删除该条数据？')) {
            $.ajax({
                url: BASE_URL + '/account/user/' + entityId,
                type: "DELETE",
                dataType: "json",
                success: function (data) {
                    $scope.pageData.items.remove(index);
                    applyAngularScope($rootScope, $scope);
                }
            });
        }
    };
}